package lb.io.apimachinery.runtime.scheme;

import lb.io.utils.Strings;

public class GroupVersion {
    private String group;

    private String version;

    public GroupVersion() {
    }

    public GroupVersion(String group, String version) {
        this.group = group;
        this.version = version;
    }

    public GroupVersion(String gv) {
        if (gv.equals("") || (gv.equals("/"))) {
            return;
        }

        switch (Strings.Count(gv, "/")) {
            case 0:
                version = gv;
                break;
            case 1:
                int i = gv.indexOf("/");
                group = gv.substring(0, i);
                version = gv.substring(i + 1);
                break;
        }
    }

    public GroupVersionKind WithKind(String kind) {
        return new GroupVersionKind(group, version, kind);
    }

    public String getGroup() {
        return group;
    }

    public void setGroup(String group) {
        this.group = group;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public boolean Empty() {
        return group.equals("") && version.equals("");
    }

    @Override
    public String toString() {
        if (Empty()) {
            return "";
        }

        if (group.equals("") && version.equals("v1")) {
            return version;
        }
        if (group.length() > 0) {
            return group + "/" + version;
        }
        return version;
    }
}
